﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace WikiCsharp
{
    using WikiCsharpCommon;

    [ComVisible(true)]
    [ProgId("Tortoise Wiki C# Plugin")]
    [Guid("ec94a7a9-4295-447f-9186-68d6ed58f2a2")]
    [ClassInterface(ClassInterfaceType.None)]
    public class Plugin : TortoisePlugin.Plugin
    {
        private WikiCsharpCommon.Settings.MySettingsManager settings_ = new WikiCsharpCommon.Settings.MySettingsManager();
        private WikiCsharpCommon.Settings.MySettingsControl settings_control_ = new WikiCsharpCommon.Settings.MySettingsControl();

        public Plugin()
            : base()
        {
            Updater.UpdaterHelper.CheckUpdate();

            settings_forms_.AddSettings(settings_, settings_control_);
        }

        protected override void SetParameters(string parameters)
        {
            base.SetParameters(parameters);
            settings_.Set(parameters);
        }

        public override bool ValidateParameters(IntPtr hParentWnd, string parameters)
        {
            base.ValidateParameters(hParentWnd, parameters);

            Validating frm = new Validating(parameters, settings_control_);

            return frm.ShowDialog() == System.Windows.Forms.DialogResult.OK;
        }

        // Done
        public override string GetCommitMessage2(IntPtr hParentWnd,
            string parameters,
            string commonURL,
            string commonRoot,
            string[] pathList,
            string originalMessage,
            string bugID,
            out string bugIDOut,
            out string[] revPropNames,
            out string[] revPropValues)
        {
            if (frmBS == null)
            {
                frmBS = new BugSelection(parameters);
            }

            return base.GetCommitMessage2(hParentWnd, parameters, commonURL, commonRoot, pathList, originalMessage, bugID, out bugIDOut, out revPropNames, out revPropValues);
        }
    }
}
